package com.neutech.neusys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.neutech.dto.Paging;
import com.neutech.neusys.mapper.SettleMapper;
import com.neutech.neusys.mapper.SysMapper;
import com.neutech.neusys.service.SysService;
import com.neutech.po.Sgory;
import com.neutech.po.Sys;
import com.neutech.po.User;

@Service
public class SysServiceImpl implements SysService{
	@Autowired
	private SysMapper sysMapper;
	@Autowired
	private SettleMapper settleMapper;

//	查询
	@Override
	public Sys findSys(int id) throws Exception {
		// TODO Auto-generated method stub
		return sysMapper.findSysById(id);
	}
	 
//	删除
	@Override
	public Sys deleteSys(int id) throws Exception {
		// TODO Auto-generated method stub
		sysMapper.deleteSysById(id);
		return new Sys();
	}
	
//	修改
	@Override
	public Sys updateSys(Sys sys) throws Exception {
		// TODO Auto-generated method stub
		sysMapper.updateSysById(sys);
		return new Sys();
	}

//	增加
	@Override
	public Sys insertSys(Sys sys) throws Exception {
		// TODO Auto-generated method stub
		sysMapper.insertSysById(sys);
		return new Sys();
	}
	

	/**
	 * 查询用户
	 * @param:用户对象
	 * @return:添加成功==1,添加失败==0
	 */
	@Override
	public List<Sgory> getSettleAll() throws Exception {
		// TODO Auto-generated method stub
		List<Sgory> settleList = settleMapper.getSettleAll();
		return settleList;
	}
	
	
	/**
	 * 增加用户
	 * @param:用户对象
	 * @return:添加成功==1,添加失败==0
	 */
	@Override
	public int addSgory(Sgory sgory) throws Exception {
		// TODO Auto-generated method stub
		int num = settleMapper.addSgory(sgory);
		return num;
	}
	/**
	 * 【科室下拉列表项-关键字过滤数据】
	 * 
	 * @param 关键字String
	 * @return List<User>
	 */
	@Override
	public List<Sgory> getSgorySelectList(String keyString) {
		keyString = "%" + keyString + "%";
		List<Sgory> dList = settleMapper.getConstantTypeSelectList(keyString);
		return dList;
	}

	/**
	 * 【获取科室列表-分页显示】
	 * 
	 * @param 分页对象Paging
	 * @return List<Department>
	 */
	@Override
	public List<Sgory> getSgory(Paging paging) {
		List<Sgory> ctList = settleMapper.getSgory(paging);
		return ctList;
	}

	/**
	 * 【获取分页列表总行数】
	 * 
	 * @param 关键字String
	 * @return int
	 */
	@Override
	public int getSgoryCount(String keyString) {
		int count = settleMapper.getSgoryCount(keyString);
		System.out.println("count" + count);
		return count;
	}

	/**
	 * 修改用户
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public Sgory updateSgory(Sgory sgory) throws Exception {
		// TODO Auto-generated method stub
		settleMapper.updateSgory(sgory);
		return new Sgory();
	}
	
	/**
	 * 删除用户
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public Sgory deleteSgory(Sgory sgory) throws Exception {
		// TODO Auto-generated method stub
		settleMapper.deleteSgory(sgory);
		return new Sgory();
	}

}
